package com.sie.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sie.entity.Role;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 角色持久层
 */
@Mapper
public interface RoleMapper extends BaseMapper<Role> {


    @Select("select r.role_name role_name, r.role_id role_id,r.on_time on_time ,r.off_time off_time ,r.role_status role_status,r.role_ps role_ps ,r.role_no role_no from  role r left join emp_role t on r.role_id = t.role_id where t.emp_id=#{id}")
    List<Role> findRoles(@Param("id") String id);

    @Delete("delete from role where role_id=#{id}")
    Integer deleteRole(String id);

    @Delete("delete from emp_role where  role_id = #{roleId}")
    Integer deleteRoleAndEmp(@Param("roleId") String roleId);

    @Delete("delete from role_authority where role_id = #{roleId}")
    Integer deleteRoleAndAuthority(@Param("roleId") String roleId);

    @Update("update role set role_name = #{roleName},role_status=#{roleStatus},role_no=#{roleNo},on_time=#{onTime},off_time=#{offTime} where role_id=#{roleId}")
    Integer updateRole(Role role);

    @Select("select * from role where role_no=#{roleNo}")
    Role findByNo(String roleNo);

    @Select("select * from role where role_name=#{roleName}")
    List<Role> findByName(String roleName);

    @Insert("insert into emp_role (emp_id,role_id) values(#{empId},#{roleId})")
    Integer setRole(@Param("empId") String empId,@Param("roleId")String roleId);

    List<Role> findByPage(Role role);

    @Delete("delete from emp_role where emp_id = #{id}")
    Integer offRolesByRoleId(String id);
}
